package com.dao;

import com.model.PermissionResource;
import com.vo.ResourceVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface PermissionResourceMapper {
    int deleteByPrimaryKey(Long id);

    int insert(PermissionResource record);

    int insertSelective(PermissionResource record);

    PermissionResource selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(PermissionResource record);

    int updateByPrimaryKey(PermissionResource record);


    List<ResourceVO> selectResourceList();
    List<ResourceVO> selectResourceListByRoleId(@Param("roleId") Long roleId);

    List<ResourceVO> selectTopResourceNodeList();

    List<ResourceVO> selectSubResourceNodeList(@Param("resourceId") Long resourceId);


    @Select("<script>" +
            " select  ID as id, NAME as name, COMMENT as comment, PARENT_ID  as parentId, LEVEL as level, URL as url, METHOD as method, " +
            "STATUS as status, CREATE_TIME as createTime, CREATED as created,\n" +
            "    UPDATE_TIME as updateTime, UPDATED as updated, SORT_NUM  as sortNum 、from  permission_resource " +
            "where ID in " +
            "<foreach item='roleId' index='index' collection='roleIdList' open='(' separator=',' close=')'>" +
            "#{roleId}" +
            "</foreach>"+
            "</script>")
    List<ResourceVO> selectResourceListByIds(@Param("roleIdList") List<Long> resourceIdList);

    ResourceVO selectResourceIdByName(@Param("name") String name);
}